package org.lanqiao.webfm.model;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import java.util.*;
import java.io.Serializable;
import java.sql.*;
import java.lang.reflect.*;

import javacommon.base.*;
import javacommon.ijdbc.*;
import javacommon.util.*;
import javacommon.web.page.*;

import org.lanqiao.webfm.model.*;
import org.slf4j.*;

/**
*@Author zhengwei
**/
public class Goods extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	//date formats
	//columns START
	/**id**/
	private Long id;
	/**名称**/
	private java.lang.String name;
	/**类别**/
	private Long typeId;
	/**价格**/
	private Double price;
	/**折扣**/
	private Double discount;
	/**描述**/
	private java.lang.String descp;
	/**供应商**/
	private java.lang.String supplier;
	/**数量**/
	private Long qty;
	/**是否推荐**/
	private java.lang.String ispreferred;
	/**图片**/
	private java.lang.String pic;
	//columns END

	public Goods(){
	}

	public Goods(Long id){
		this.id = id;
	}

	public void setId(Long value) {
		this.id = value;
	}
	/**id**/
	public Long getId() {
		return this.id;
	}
	public void setName(java.lang.String value) {
		this.name = value;
	}
	/**名称**/
	public java.lang.String getName() {
		return this.name;
	}
	public void setTypeId(Long value) {
		this.typeId = value;
	}
	/**类别**/
	public Long getTypeId() {
		return this.typeId;
	}
	public void setPrice(Double value) {
		this.price = value;
	}
	/**价格**/
	public Double getPrice() {
		return this.price;
	}
	public void setDiscount(Double value) {
		this.discount = value;
	}
	/**折扣**/
	public Double getDiscount() {
		return this.discount;
	}
	public void setDescp(java.lang.String value) {
		this.descp = value;
	}
	/**描述**/
	public java.lang.String getDescp() {
		return this.descp;
	}
	public void setSupplier(java.lang.String value) {
		this.supplier = value;
	}
	/**供应商**/
	public java.lang.String getSupplier() {
		return this.supplier;
	}
	public void setQty(Long value) {
		this.qty = value;
	}
	/**数量**/
	public Long getQty() {
		return this.qty;
	}
	public void setIspreferred(java.lang.String value) {
		this.ispreferred = value;
	}
	/**是否推荐**/
	public java.lang.String getIspreferred() {
		return this.ispreferred;
	}
	public void setPic(java.lang.String value) {
		this.pic = value;
	}
	/**图片**/
	public java.lang.String getPic() {
		return this.pic;
	}
	
	private Set ordersDetails = new HashSet(0);
	public void setOrdersDetails(Set ordersDetail){
		this.ordersDetails = ordersDetail;
	}
	
	public Set getOrdersDetails() {
		return ordersDetails;
	}
	
	private Type type;
	
	public void setType(Type type){
		this.type = type;
	}
	
	public Type getType() {
		return type;
	}
	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("Id",getId())
			.append("Name",getName())
			.append("TypeId",getTypeId())
			.append("Price",getPrice())
			.append("Discount",getDiscount())
			.append("Descp",getDescp())
			.append("Supplier",getSupplier())
			.append("Qty",getQty())
			.append("Ispreferred",getIspreferred())
			.append("Pic",getPic())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getId())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof Goods == false) return false;
		if(this == obj) return true;
		Goods other = (Goods)obj;
		return new EqualsBuilder()
			.append(getId(),other.getId())
			.isEquals();
	}

	public void setPicList(List<String> paths) {
		StringBuilder sb = new StringBuilder();
		for (Iterator iter = paths.iterator(); iter.hasNext();) {
			String path = (String) iter.next();
			sb.append(path);
			if (iter.hasNext()) {
				sb.append(",");
			}
		}
		setPic(sb.toString());
	}
	public List<String> getPicList() {
		return Arrays.asList(pic.split(","));
	}
	public List<String> getSmallPicList() {
		List<String> list =  getPicList();
		List<String> smallList = new ArrayList<String>();
		for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) {
			String path = iterator.next();
			if (path.contains("_big")) {
			}else {
				smallList.add(path);
			}
		}
		return smallList;
	}
	public String getFirstBigPic(){
		String path=getPicList().get(0);// /webdata/goodsicon/6a1f3023-d15e-4845-b1f4-1caa81da31bb/show1.jpg
		String _path = path.substring(0, path.lastIndexOf("/"))+"/show1_big.jpg";
		return _path;
	}
	public String getFirstSmallPic(){
		String path=getPicList().get(0);// /webdata/goodsicon/6a1f3023-d15e-4845-b1f4-1caa81da31bb/show1.jpg
		String _path = path.substring(0, path.lastIndexOf("/"))+"/show1.jpg";
		return _path;
	}
}

